package com.example.demo2.util;

import javafx.event.ActionEvent;
import javafx.scene.control.Button;

public class SetSeatButton {
    String buttonName;

    public void addColorAction(ActionEvent event) {
        Button button = SetSeatButton("button");
        String buttonText = button.getText();
        String beginText = buttonText.substring(1, 1);
        String endText = buttonText.substring(3, 3);
        button.setId("button" + beginText + endText);
        button.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button);
    }

    public static Button SetSeatButton(String buttonName) {
        Button button = new Button();
        button.setId(buttonName);
        return button;
    }

    public static void changeSeatCondition(String seat, Button button){
        String filename = seat;
        String id = button.getText();
        String reversed = new String();
        if (button.getStyle() == "-fx-border-color: #EE1169;") {
            reversed = "true";
        }else{
            reversed = "false";
        }
        String vip = new String();
        if (id == "0101" || id == "0102" || id == "0103" || id == "0104") vip = "true";
        else vip = "false";
        //写入
        String data = String.format("{\n" +
                "      \"id\" : \"%s\",\n" +
                "      \"vip\" : %s,\n" +
                "      \"reserved\" : %s\n" +
                "    }", id, vip, reversed);
        com.example.demo2.dao.JsonWriter.saveDataToFile(filename, data);
    }
}
